#include "stdafx.h"
#include "MapRect.h"


CMapRect::CMapRect()
{
}


CMapRect::~CMapRect()
{
}


void CMapRect::InitRect(CWnd* pWnd)
{
	m_pWnd = pWnd;
	pWnd->GetClientRect(m_rect);
	CWnd* p = pWnd ->GetWindow(GW_CHILD);
	CRect rect;
	CMap<UINT, UINT, CRect, const CRect&>&map = *this ;
	while (p)
	{
		UINT nID = p->GetDlgCtrlID();
		if (nID != IDC_STATIC)
		{
			p->GetWindowRect(rect);
			pWnd ->ScreenToClient(rect);
			map[nID] = rect;
		}
		p = p->GetWindow(GW_HWNDNEXT);

	}
}


void CMapRect::MoveCenter(UINT nID)
{
	CWnd* p = m_pWnd->GetDlgItem(nID);
	if (!p)
		return;
	CRect rect = GetRect(nID);
	int nWidth = rect.Width();
	rect.left = (m_size.cx- nWidth) / 2;
	rect.right = rect.left + nWidth;
	p->MoveWindow(rect);
}

void CMapRect::MoveRight(UINT nID)
{
	CWnd* p = m_pWnd->GetDlgItem(nID);
	if (!p)
		return;
	CRect rect = GetRect(nID);
	int nRight = m_rect.right - rect.right;
	int nWidth = rect.Width();
	rect.right = m_size.cx - nRight;
	rect.left = rect.right - nWidth;
	p->MoveWindow(rect);
}

void CMapRect::FlateRight(UINT nID)
{
	CWnd* p = m_pWnd->GetDlgItem(nID);
	if (!p)
		return;
	CRect rect = GetRect(nID);
	int nRight = m_rect.right - rect.right;
	rect.right = m_size.cx - nRight;
	p->MoveWindow(rect);
}

void CMapRect::FlateRB(UINT nID)
{
	CWnd* p = m_pWnd->GetDlgItem(nID);
	if (!p)
		return;
	CRect rect = GetRect(nID);
	int nRight = m_rect.right - rect.right;
	rect.right = m_size.cx - nRight;
	int nBottom = m_rect.bottom - rect.bottom;
	rect.bottom = m_size.cy - nBottom;
	p->MoveWindow(rect);
}
